package Actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.RowSet;

import model.StudentModel;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DbException;

public class residencyAction extends Action{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		
		forms.residencyform a = (forms.residencyform) form;

		if(a.getResidency() == null){
			a.setResidency( (String)(request.getAttribute("residency")));
		}
		request.getSession().setAttribute("residency", a.getResidency());
	
		RowSet crsUniversities = null;
		try {
			crsUniversities = StudentModel.getUnivercities();
		} catch (DbException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		// Store the RowSet in the request scope
		request.setAttribute("crsUniversities", crsUniversities);
		
		return mapping.findForward("residencysuccess");
	}
}